﻿<Window x:Class="Brjnk.GpxExplorer.UI.ManagePhotoWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:loc="clr-namespace:Brjnk.GpxExplorer.Localization"
        WindowStartupLocation="CenterOwner"
        Title="{loc:Loc titleManagePhotos}" MinWidth="600" MinHeight="600">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition MinWidth="150" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition Height="Auto"></RowDefinition>
        </Grid.RowDefinitions>

        <GridSplitter Grid.Column="1" HorizontalAlignment="Center" Width="5" Style="{StaticResource GridSplitterStyle}" />

        <!--Listview fotek-->
        <ListView ItemsSource="{Binding Photos.Collection}" Name="lv" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="IsSelected" Value="{Binding IsSelected}" />
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid Height="48">
                        <Grid.RowDefinitions>
                            <RowDefinition  Height="Auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>
                        <Image Width="48" Height="48" Margin="3" Grid.RowSpan="2" Source="{Binding Thumbnail}">
                            <Image.LayoutTransform>
                                <RotateTransform Angle="{Binding Orientation, Converter={StaticResource ResourceKey=PhotoOrientationConverter}}" />
                            </Image.LayoutTransform>
                        </Image>
                        <TextBlock Grid.Column="1" Text="{Binding FileName}" />
                        <TextBlock FontSize="9" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap" Text="{Binding FullName}" />
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

        <!--Podrobnosti o fotce, zobrazí se, pokud je vybrána právě 1 fotka-->
        <Grid Grid.Column="2" DataContext="{Binding ElementName=lv, Path=SelectedItem}">
            <Grid.Style>
                <Style TargetType="Grid">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ElementName=lv, Path=SelectedItems.Count}" Value="1">
                            <Setter Property="Grid.Visibility"  Value="Visible" />
                        </DataTrigger>
                    </Style.Triggers>
                    <Setter Property="Visibility" Value="Collapsed" />
                </Style>
            </Grid.Style>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>

                <RowDefinition Height="32" />
                <RowDefinition Height="32" />
                <RowDefinition Height="32" />
                <RowDefinition Height="32" />
                <RowDefinition Height="32" />
                <RowDefinition Height="32" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <TextBlock VerticalAlignment="Center" Grid.Row="0" Text="{loc:Loc managePhotoName}" />
            <TextBlock VerticalAlignment="Center" Grid.Row="0" Grid.Column="1" Text="{Binding Path=FullName}" />
            <TextBlock VerticalAlignment="Center" Grid.Row="1" Text="{loc:Loc managePhotoSize}" />
            <TextBlock VerticalAlignment="Center" Grid.Row="1" Grid.Column="1">
            <TextBlock.Text>
                <MultiBinding Converter="{StaticResource SizeStringConverter}">
                    <Binding Path="PixelWidth" />
                    <Binding Path="PixelHeight" />
                </MultiBinding>
            </TextBlock.Text>
            </TextBlock>
            <TextBlock VerticalAlignment="Center" Grid.Row="2" Text="{loc:Loc managePhotoDate}" />
            <TextBlock VerticalAlignment="Center" Grid.Row="2" Grid.Column="1" Text="{Binding Path=CreationTime}" />
            <TextBlock VerticalAlignment="Center" Grid.Row="3" Text="{loc:Loc managePhotoCorrection}" />
            <TextBox   VerticalAlignment="Center" Grid.Row="3" Grid.Column="1" Text="{Binding Path=TimeCorrection}" />
            <TextBlock VerticalAlignment="Center" Grid.Row="4" Text="{loc:Loc managePhotoCorrected}" />
            <TextBlock VerticalAlignment="Center"  Grid.Row="4" Grid.Column="1" Text="{Binding Path=CorrectedCreationTime}" />
            <TextBlock VerticalAlignment="Center" Grid.Row="5" Text="{loc:Loc managePhotoOrientation}" />
            <TextBlock VerticalAlignment="Center"  Grid.Row="5" Grid.Column="1" Text="{Binding Path=Orientation}" />

            <ItemsControl Grid.ColumnSpan="2" Grid.Row="6" ItemsSource="{Binding Path=Locations}" BorderBrush="LightGray" BorderThickness="2">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <UniformGrid Columns="3">
                            <UniformGrid.Style>
                                <Style>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Path=(ItemsControl.AlternationIndex), RelativeSource={RelativeSource Mode=Self}}" Value="0">
                                            <Setter Property="UniformGrid.Background" Value="{StaticResource AlternationBrush}" />
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </UniformGrid.Style>
                            <TextBlock FontWeight="Bold" Text="{Binding Locator.Source.Name}" ToolTip="{loc:Loc managePhotoTrackName}" />
                            <TextBlock Text="{Binding Position}"  ToolTip="{loc:Loc managePhotoCoordinates}" />
                            <TextBlock Text="{Binding Elevation, Converter={StaticResource ElevationConverter}}"  ToolTip="{loc:Loc managePhotoElevation}" />
                        </UniformGrid>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>

            <TextBlock Grid.Row="7" TextWrapping="Wrap" Grid.ColumnSpan="2" Text="{loc:Loc managePhotoExifNotFound}">
            <TextBlock.Style>
                <Style BasedOn="{StaticResource WarningStyle}" TargetType="TextBlock">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding FileCreationTimeUsed}" Value="False">
                        <Setter Property="Visibility" Value="Collapsed" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TextBlock.Style>
            </TextBlock>

            <Button Grid.Row="8" Grid.Column="0"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center"
                    Content="{loc:Loc managePhotoRemove}"
                    CommandParameter="{Binding}"
                    Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}, Path=DataContext.RemoveCommand}" />

            <Button Grid.Row="8" Grid.Column="1"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center"
                    Content="{loc:Loc managePhotoOpen}"
                    CommandParameter="{Binding Path=FullName}"
                    Command="{StaticResource RunCommand}" />

            <Image HorizontalAlignment="Center" Grid.ColumnSpan="2" Grid.Row="9">
                <Image.Source>
                    <PriorityBinding>
                        <Binding Path="PhotoFull" IsAsync="True" />
                        <Binding Path="Thumbnail" />
                    </PriorityBinding>
                </Image.Source>
                <Image.LayoutTransform>
                    <RotateTransform Angle="{Binding Orientation, Converter={StaticResource ResourceKey=PhotoOrientationConverter}}" />
                </Image.LayoutTransform>
            </Image>
        </Grid>

        <Grid Grid.Column="2" HorizontalAlignment="Center" VerticalAlignment="Center">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.Style>
                <Style TargetType="Grid">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ElementName=lv, Path=SelectedItems.Count}" Value="0">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding ElementName=lv, Path=SelectedItems.Count}" Value="1">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Grid.Style>

            <Button Content="{loc:Loc managePhotoMultiRemove}" Command="{Binding RemoveCommand}" CommandParameter ="{Binding ElementName=lv, Path=SelectedItems}" />
            <Button Grid.Row="1" Content="{loc:Loc managePhotoMultiReload}" Command="{Binding ReloadCommand}" CommandParameter ="{Binding ElementName=lv, Path=SelectedItems}" />
            <Button Grid.Row="2" Content="{loc:Loc managePhotoMultiCorrect}" Command="{Binding SetTimeCorrectionCommand}" CommandParameter ="{Binding ElementName=lv, Path=SelectedItems}" />
            <TextBlock Grid.Row="3" Text="{loc:Loc managePhotoMultiCount, Binding={Binding ElementName=lv, Path=SelectedItems.Count}}" />
        </Grid>

        <StackPanel HorizontalAlignment="Right" Grid.Row="1" Grid.Column="2">
            <Button Content="{loc:Loc managePhotoLoad}" Command="{Binding LoadCommand}" />
        </StackPanel>
    </Grid>
</Window>